ans = 0
a = [[0] * (5 - i) for i in range(5)]
a[0] = [1, 0, 1, 0, 1]

def dfs(x, y):  # x为层号，y为门编号
    global ans
    if x == 5:
        if a[4][0] == 1:
            ans += 1
        return

    for i in range(3):
        if i == 0:
            a[x][y] = a[x-1][y] & a[x-1][y+1]
        elif i == 1:
            a[x][y] = a[x-1][y] | a[x-1][y+1]
        else:
            a[x][y] = a[x-1][y] ^ a[x-1][y+1]

        if x + y < 4:
            dfs(x, y + 1)
        else:
            dfs(x + 1, 0)

dfs(1, 0)
print(ans)